package com.haohe.wx.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @Title 生成随机码
 * 
 * @Description TODO
 * @author liming.zhao@haohedata.com
 * @date 2015-6-29 
 * @time 下午3:16:55
 */

public enum RandomStringGenerate {

	INSTANCE {

		@Override
		public synchronized String get(int count) {
			StringBuffer randomStringBuffer = new StringBuffer();
			Random random = new Random();
			for (int i = 0; i < count; i++) {
				randomStringBuffer.append(randString.charAt(random.nextInt(randString.length())));
			}
			return randomStringBuffer.toString();
		}

		@Override
		public synchronized String createNumber18() {
			Date date = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); // 年月日时分秒
			String systemTime = sdf.format(date);
			int round = (int) Math.round(Math.random() * 9999 + 1); // 0-9999随机数
			DecimalFormat df1 = new DecimalFormat("0000"); // 随机数格式化不足四位前面补0
			return systemTime + df1.format(round);
		}

		@Override
		public String createCusNo() {
			String rand = null;
			SimpleDateFormat format = null;
			rand = String.valueOf(new Random().nextInt(100000));
			while (rand.length() < 5) {
				rand = "0" + rand;
			}
			format = new SimpleDateFormat("yyyyMMddHHmmss");
			format.format(new Date());
			return format.format(new Date()) + rand;
		}

	};

	protected String randString = "0123456789";

	public abstract String get(int count);

	/**
	 * @return
	 */
	public abstract String createNumber18();

	/**
	 * 创建客户号
	 * 
	 * @return
	 */
	public abstract String createCusNo();

}